package servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import dao.UserDao;
import dao.impl.UserDaoImpl;
import entity.User;
import service.UserService;
import service.impl.UserServiceImpl;


public class SywSelectUserName extends HttpServlet {
	private UserDao ud = new UserDaoImpl();
	private UserService us = new UserServiceImpl();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("application/json;charset=utf-8");
		String sywUserName = request.getParameter("sywUserName");//input标签获取的值
		String[] sywPassword = request.getParameterValues("sywPassword");//input标签获取密码
		//根据前端id获取到的value设置key取值
		String inputUserName = request.getParameter("inputUserName");
		List<User> selectAllUser = us.selectAllUser();
		boolean falg = false;
		if(selectAllUser!=null){
			for (User user : selectAllUser) {
				if(user.getUsername().equals(inputUserName)){
					falg = true;
					break;
				}
			}
		}
		
		response.getWriter().print(JSON.toJSONString(falg));
		
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doGet(request, response);
	}

}
